//
//  ActionItemCell.m
//  com.modada.new
//
//  Created by ferver7 on 2019/4/23.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "ActionItemCell.h"


@implementation ActionItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selfCollectionView.delegate = self;
    self.selfCollectionView.dataSource = self;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 3;
}
- (IBAction)delList:(UIButton *)sender { //删除
    self.actionBlock(1,sender);
}
- (IBAction)verbAction:(UIButton *)sender {//上下架
    self.actionBlock(2,sender);
}
-(void)reloadViewForModel:(id)model
{
    ActionItemModel * itemModel = (ActionItemModel *)model;
    _objModel = itemModel;
    [self.selfCollectionView reloadData];
    self.nameLabel.text = itemModel.storeName;
    self.expLabel.text = itemModel.content;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",itemModel.price];
    self.addressLabel.text = [NSString stringWithFormat:@"%@  %@",itemModel.city,itemModel.area];
    self.timeNumsLabel.text = [NSString stringWithFormat:@"%@  %@人浏览",[NSDate compareCurrentTime:itemModel.createTime],itemModel.browseNumber];
    [self.logoImage sd_setImageWithURL:[NSURL URLWithString:itemModel.userImage] placeholderImage:mImageByName(@"")];
    if (itemModel.state.integerValue == 1) {
        [self.verbBtn setTitle:@"下架" forState:UIControlStateNormal];
        [self.verbBtn setTitleColor:[UIColor AxcUI_colorWithHexColor:@"#666666"] forState:UIControlStateNormal];
    }else{
        [self.verbBtn setTitle:@"上架" forState:UIControlStateNormal];
        [self.verbBtn setTitleColor:[UIColor AxcUI_colorWithHexColor:@"#6933DB"] forState:UIControlStateNormal];
    }
    
}
#pragma mark uicollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray * imagesArr = [self.objModel.image componentsSeparatedByString:@","];
    return imagesArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray * imagesArr = [self.objModel.image componentsSeparatedByString:@","];
    UICollectionViewCell * cell = mGetCollectionViewCell(@"itemCell", indexPath);
    UIImageView * logoImage = mViewByTag(cell.contentView, 100, UIImageView);
    [logoImage sd_setImageWithURL:imagesArr[indexPath.row] placeholderImage:mImageByName(@"")];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    //    125/170 = (mScreenWidth-60)*2/5 / h
    return CGSizeMake((mScreenWidth-115)/3, (mScreenWidth-115)/3);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
//这个是两行cell之间的间距（上下行cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 10;
}
//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
+(CGFloat)cellForHeightFor:(ActionItemModel *)itemModel
{
    NSArray * imagesArr = [itemModel.image componentsSeparatedByString:@","];
    if (imagesArr.count <= 3) {
        return 120 + (mScreenWidth-115)/3;
    }else{
         return 130 + (mScreenWidth-115)*2/3;
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
